

import { _decorator, Color, Label, Node, Sprite, Tween, tween, UITransform, Vec3 } from 'cc';
import { BaseUI } from '../../framework/base/BaseUI';

const { ccclass, property } = _decorator;

@ccclass('UITips')
export class UITips extends BaseUI {
    @property({ type: Node, tooltip: "layout节点" })
    tipsNode: Node = null;
    @property({ type: Label, tooltip: "文字" })
    tips: Label = null;

    private tipSprite: Sprite
    private tweenAction: Tween<Node>
    private text: string = ""
    onLoad() {
        this.tipSprite = this.tipsNode.getComponent(Sprite)
        this.tweenAction = tween(this.tipsNode)
            .to(0.1, { scale: new Vec3(1, 0.1, 1) })
            .to(0.1, { scale: new Vec3(1, 1, 1) })
            .delay(0.5)
            .by(1, { position: new Vec3(0, 100) })
            .to(0.3, { scale: new Vec3(1, 0, 1) })
            .call(() => {
                this.tipsNode.setPosition(0, 0)
                this.closeUI();
            })
            this.node.getComponent(UITransform).priority = 10000
    }
    init(str: string) {
        this.text = str;
    }
    refreshUI(str: string) {
        this.text = str;
        this.tweenAction.stop()
        this.tipsNode.setScale(0, 1);
        this.tipSprite.color = new Color(255, 255, 255, 255)
        this.tips.updateRenderData(true)
        this.tipsNode.setPosition(0, 0)

        this.tips.string = this.text;
        this.tipsNode.setScale(0, 0.1);
        this.tweenAction.start();
    }
    start() {
        this.tipsNode.setScale(0, 1);
        this.tipSprite.color = new Color(255, 255, 255, 255)
        this.tips.updateRenderData(true)
        this.tipsNode.setPosition(0, 0)
        this.tips.string = this.text;
        this.tipsNode.setScale(0, 0.1);
        this.tweenAction.start();
    }

}
